package tech.bmatch.meituan.service.impl;

import tech.bmatch.meituan.model.Dishes;
import tech.bmatch.meituan.service.DishesService;
import tech.bmatch.meituan.util.MerchantUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DishesServiceImpl implements DishesService {
    private Map<String, Dishes> dishess;

    public void adds(Dishes dishes) {
        if (dishess == null) {
            dishess = new HashMap<String, Dishes>();
        }
        if (dishes == null) {
            return;
        }
        dishess.put(dishes.getId(), dishes);
    }

    public List<Dishes> search(String merchantName) {
        List<Dishes> dishesList = new ArrayList<Dishes>();
        for (Map.Entry<String, Dishes> dishesEntry : dishess.entrySet()) {
            Dishes dishes = dishesEntry.getValue();
            String name = MerchantUtil.equal(merchantName, dishes.getMerchantName());
            dishes.setMerchantName(name);
            dishesList.add(dishes);
        }
        return dishesList;
    }
}
